package com.cyandpos.pad.cateringformat.opentable;

import com.cyandpos.pad.posdata.DinnerTable;
import com.cyandpos.pad.posdata.TableReserve;

import java.util.List;

/**
 * Created by xin on 2021/8/30
 * desc:
 */
public class PresentFragmentOpenTable {

    private ImplViewFragmentOpenTable mView;
    private ImplModelFragmentOpenTable mModel;


    public PresentFragmentOpenTable(ImplViewFragmentOpenTable mView) {
        this.mView = mView;
        mModel = new ModelFragmentOpenTable();
    }
    /**
     *  查询餐桌预定信息
     * @param stableId 桌号
     */
    public void queryTableReserveInfo(int stableId){
        mView.showProgress("查询餐桌预定信息中...");
        mModel.queryTableReserveInfo(stableId, new ImplModelFragmentOpenTable.onQueryTableReserveListener() {
            @Override
            public void onQueryTableReserveSuccess(List<TableReserve> tableList) {
                mView.dismissProgress();
                mView.showDinnerTableReserveInfo(tableList);
            }

            @Override
            public void onQueryTableReserveFailure(String errorMsg) {
                mView.dismissProgress();
                mView.requestNetFail(errorMsg);
            }
        });
    }

    /**
     *  刷新餐桌状态
     * @param stableState -1全部状态
     */
    public void queryTableStatusInfo(int stableState){
        mView.showProgress("更新餐桌状态中...");
        mModel.queryTableStatusInfo(stableState, new ImplModelFragmentOpenTable.onQueryTableStatusListener() {
            @Override
            public void onQueryTableStatusSuccess(List<DinnerTable> tableList) {
                mView.dismissProgress();
                mView.refreshDinnerTableInfo(tableList);
            }

            @Override
            public void onQueryTableStatusFailure(String errorMsg) {
                mView.dismissProgress();
                mView.requestNetFail(errorMsg);
            }
        });
    }

    /**
     * 清桌
     * @param stableId 餐桌id
     * @param stableState 清桌后的状态
     */
    public void clearTableStatus(int stableId,int stableState){
        mView.showProgress("餐桌状态转换中...");
        mModel.clearTableStatus(stableId,stableState, new ImplModelFragmentOpenTable.onClearTableStatusListener() {
            @Override
            public void onClearTableStatusSuccess() {
                mView.dismissProgress();
                mView.clearDinnerTableSuccess();
            }

            @Override
            public void onClearTableStatusFailure(String errorMsg) {
                mView.dismissProgress();
                mView.requestNetFail(errorMsg);
            }
        });
    }
}
